package design_pattern.proxy.test2;

import java.lang.reflect.Proxy;

/**
 * Created by WeiDingKuo on 2017/10/25 19:49
 */
public class ProxyFactory {
    private Object target;

    public ProxyFactory(Object target) {
        this.target = target;
    }

    public Object getProxyInstance() {
        return Proxy.newProxyInstance(this.target.getClass().getClassLoader(),
                this.target.getClass().getInterfaces(),
                (proxy, method, args) -> {
                    System.out.println("before");
                    Object returnValue = method.invoke(this.target, args);
                    System.out.println("after");
                    return returnValue;
                });
    }
}
